package br.com.fogas.medicao.tabs;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;

public class ViewPagerAdapter extends FragmentStatePagerAdapter {
    
	private List<Fragment> fragments;

	public ViewPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
		super(fm);
		this.fragments = fragments;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		Fragment fragment = (Fragment) object;
	    FragmentManager manager = fragment.getFragmentManager();
	    FragmentTransaction trans = manager.beginTransaction();
	    trans.remove(fragment);
	    trans.commit();
	}

	@Override
	public Fragment getItem(int position) {
		Fragment fragment = this.fragments.get(position);
		return fragment;
	}

	@Override
	public int getCount() {
		return fragments.size();
	}
}